package com.boilerCloud.controller.sys;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.boilerCloud.dataSource.LogAnnotation;
import com.boilerCloud.dto.HzlqswPage;
import com.boilerCloud.dto.sys.AppVersion;
import com.boilerCloud.dto.sys.ReqResult;
import com.boilerCloud.service.sys.IAppVersionService;


@RestController
@RequestMapping("/version/")
public class AppVersionControler {
	private static final Logger log = LoggerFactory.getLogger(AppVersionControler.class);
	@Resource
	private IAppVersionService service;


	@RequestMapping(value = "versionList")
	public ModelAndView versionList() {
		return new ModelAndView("/views/sys/appVersion.html");
	}
	
	

	/**
	 * 查询app版本列表
	 * @param grade
	 * @param yema
	 * @param length
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "qryVersionList", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult qryVersionList(@ModelAttribute AppVersion model ,
			@RequestParam(required = true) int yema,
			@RequestParam(required = true) int length,HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			
			HzlqswPage<AppVersion> page = new HzlqswPage<AppVersion>();
			page.setCurPage(yema);
			page.setPageSize(length);
			service.qryList(model,page);
			rst.setReturnObject(page);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("查询app版本列表失败");
			log.error("查询app版本列表异常",e);
			return rst;
		}
	}
	
	/**
	 * 修改app版本信息
	 * @param device
	 * @param request
	 * @return
	 */
	@LogAnnotation("修改APP版本")
	@RequestMapping(value = "editAppVersion", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult editAppVersion(
			@ModelAttribute AppVersion model ,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			service.edit(model);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("修改app版本信息失败");
			log.error("修改app版本信息异常",e);
			return rst;
		}
	}
	/**
	 * 新增app版本
	 * @param device
	 * @param request
	 * @return
	 */
	@LogAnnotation("新增APP版本")
	@RequestMapping(value = "addAppVersion", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult addAppVersion(
			@ModelAttribute AppVersion model ,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			service.save(model);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("新增app版本信息失败");
			log.error("新增app版本信息异常",e);
			return rst;
		}
	}
	
	/**
	 * 删除app版本
	 * @param businessNo
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "delAppVersion", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8")
	public ReqResult delModel(
			@RequestParam(required = true) int id,
			HttpServletRequest request) {
		ReqResult rst = new ReqResult();
		try {
			service.del(id);
			rst.setResultCode(ReqResult.resultCode_Success);
			return rst;


		} catch (Exception e) {
			rst.setResultCode(ReqResult.resultCode_error);
			rst.setReturnObject("删除app版本失败");
			log.error("删除app版本异常",e);
			return rst;
		}
	}
	

	

}
